package com.yl.drug_management.mapper;

import com.yl.drug_management.pojo.StockOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StockOrderMapper {

    int insertSelective(StockOrder record);

    void insertMqMessage(@Param("sid") Integer sid, @Param("userid") Integer userId);

    void updateMqMessage(@Param("sid") Integer sid, @Param("userid") Integer userId);

    Integer selectCountMqMessageHandle(@Param("sid") Integer sid, @Param("userid") Integer userId);

    void insertMqMessageHandle(@Param("sid") Integer sid, @Param("userid") Integer userId);

    @Select("SELECT id,sid from stock_order order by id desc limit 1")
    StockOrder selectLastestInsert();

    @Select("select paied from stock_order where id = #{id}")
    Integer selectOrderStatus(Integer id);

    @Update("update stock_order set paied = -1 where id = #{id}")
    void updateOrderStatus(Integer id);

    @Update("update stock set count=count+1 where id = #{sid}")
    void addStockCount(Integer sid);

    @Update("update stock_order set paied = 1 where sid=#{sid} AND user_id=#{userid} order by create_time desc limit 1")
    void updateOrderStatus2One(@Param("sid") int sid,@Param("userid") String userid);

    @Select("select sid,create_time as createTime,name,user_id as userId,paied from stock_order")
    List<StockOrder> selectAllOrder();
}
